home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / QuickTime VR / MacOS / QuickDraw™ 3D 1.0.6F4 SDK / Development / 3DMF parser / 0.9 version / MFBINUTL.H < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-24  |  1.7 KB  |  58 lines  |  [TEXT/MPS ]

  1. #ifndef    MF3D_BINARYUTILS_H
  2. #define    MF3D_BINARYUTILS_H
  3. /*==============================================================================
  4.  *
  5.  *    File:        MFBINUTL.H
  6.  *
  7.  *    Function:    Binary swap utilities
  8.  *
  9.  *    Author(s):    Rick Wong (RWW)
  10.  *
  11.  *    Copyright:    (c) 1995 by Apple Computer, Inc., all rights reserved.
  12.  *
  13.  *    Change History (most recent first):
  14.  *        Fabio    Changed file name to 8 characters
  15.  *        F2H_RWW    File created.
  16.  *==============================================================================
  17.  */
  18. #if defined(__COMPILING_ON_MACINTOSH__)
  19. #pragma once
  20. #endif
  21.  
  22. #include "MFASSERT.H"
  23.  
  24. #define    MF3D_Swap4(a, b)    (*(long *)&(a)) ^= (*(long *)&(b));                \
  25.                             (*(long *)&(b)) ^= (*(long *)&(a));                \
  26.                             (*(long *)&(a)) ^= (*(long *)&(b))
  27.  
  28. #define    MF3D_ByteSwap2(n)    (*(long*)&(n)) =                                \
  29.                                 (((*(long*)&(n)) & 0xFF00) >> 8) |            \
  30.                                 (((*(long*)&(n)) & 0x00FF) << 8)
  31.  
  32. #define    MF3D_ByteSwap4(n)    (*(long*)&(n)) =                                \
  33.                                 (((*(long*)&(n)) & 0xFF000000) >> 24)    |    \
  34.                                 (((*(long*)&(n)) & 0x00FF0000) >> 8)    |    \
  35.                                 (((*(long*)&(n)) & 0x0000FF00) << 8)    |    \
  36.                                 (((*(long*)&(n)) & 0x000000FF) << 24)
  37.  
  38. #define    MF3D_ByteSwap8(n)    MF3D_ByteSwap4(*(long *)&(n));                    \
  39.                             MF3D_Swap4(*(long *)&(n), *(((long *)&(n))+1));    \
  40.                             MF3D_ByteSwap4(*(long *)&(n));
  41.  
  42. #define    MF3D_ByteSwap(bytes, n)        MFASSERT(bytes == 8 || bytes == 4 ||    \
  43.                                             bytes == 2);                    \
  44.                                     if (bytes == 8)                            \
  45.                                     {    MF3D_ByteSwap8(n);                    \
  46.                                     }                                        \
  47.                                     else if (bytes == 4)                    \
  48.                                     {    MF3D_ByteSwap4(n);                    \
  49.                                     }                                        \
  50.                                     else if (bytes == 2)                    \
  51.                                     {    MF3D_ByteSwap2(n);                    \
  52.                                     }                                        \
  53.                                     else                                    \
  54.                                     {    MFASSERT(bytes);                    \
  55.                                     }
  56.  
  57. #endif
  58.